<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Authenticated_page_c extends CI_Controller {
        public function __construct() {
            parent::__construct();
            $this->load->model(array('post_m','subscription_m','groups_m', 'user_m'));
            $this->load->helper(array('form', 'url', 'html'));
            $this->load->library(array('form_validation', 'upload', 'image_lib', 'pagination'));
        }
        
        public function index() {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
            $data['years'] = $this->post_m->get_year();
            $result = $this->post_m->count_bulletin_group_posts($this->session->userdata('user_id'));
            $data['group_info'] = $this->groups_m->get_all_subscribed_groups($this->session->userdata('user_id'));
            $data['segment'] = $this->uri->segment(2);
            $data['header_title'] = "All Posts";
            $data['day'] = array(
                'name' => 'day',
                'id' => 'day_filter',
                'type' => 'text'
            );
            $data['submit_day'] = array(
                'name' => 'submit_day',
                'id' => 'submit_day_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['year'] = array(
                'name' => 'year',
                'id' => 'year_filter',
                'type' => 'text'
            );
            $data['submit_year'] = array(
                'name' => 'submit_year',
                'id' => 'submit_year_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            
            $config = array();
            $config["base_url"] = site_url('/authenticated_page_c/index/');
            $config["total_rows"] = sizeof($this->post_m->get_bulletin_group_posts($this->session->userdata('user_id')));
            $config["per_page"] = 5;
            $config["uri_segment"] = 3;
            $config['num_links'] = 10;
            $config['full_tag_open'] = '<span id=page_link>';
            $config['full_tag_close'] = '</span>';
            $config['first_link'] = 'First';
            $config['first_tag_open'] = '<span id=first_link>';
            $config['first_tag_close'] = '<span>';
            $config['last_link'] = 'Last';
            $config['last_tag_open'] = '<span id=last_link>';
            $config['last_tag_close'] = '<span>';
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span id=prev_link>';
            $config['prev_tag_close'] = '<span>';
            $config['next_link'] = 'Next';
            $config['nex_tag_open'] = '<span id=next_link>';
            $config['next_tag_close'] = '<span>';

            $this->pagination->initialize($config);

            $page = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
            $data["bulletin"] = $this->post_m->fetch_bulletin_group_post($config["per_page"], $page, $this->session->userdata('user_id'));
            $data["links"] = $this->pagination->create_links();
            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            if($result !== 0) {
                $this->load->view('authenticated/bulletin_v', $data);
            } else {
                $this->load->view('authenticated/result_empty', $data);
            }
            $this->load->view('footer_v', $data);
        }
        
        function groups() {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
            $data['user_id'] = $this->session->userdata('user_id');
            $data['role_id'] = $this->session->userdata('role_id');
            $data['rolename'] = $this->session->userdata('rolename');
            
            $data['my_groups'] = $this->subscription_m->get_groups_subscribed_by($data['user_id']);
            
            for($i = 0; $i < count($data['my_groups']); $i++) {
                $admins = $this->groups_m->getGroupAdmins($data['my_groups'][$i]['group_id']);
                
                $data['my_groups'][$i]['admins'] = $admins;
            }
            
            $data['more_groups'] = $this->subscription_m->get_groups_notby($data['user_id']);
            
            $this->load->view('authenticated/fragments/header_v', $data);
            $this->load->view('authenticated/groups_v', $data);
            $this->load->view('administrator/fragments/footer_v', $data);
        }
        
        function sort_groups() {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
            $data['user_id'] = $this->session->userdata('user_id');
            $data['role_id'] = $this->session->userdata('role_id');
            $data['rolename'] = $this->session->userdata('rolename');
            //$dept_id = $this->session->userdata('dept_id');
            
            $data['my_groups'] = $this->subscription_m->get_groups_subscribed_by_order_name($data['user_id']);
            
            for($i = 0; $i < count($data['my_groups']); $i++) {
                $admins = $this->groups_m->getGroupAdmins($data['my_groups'][$i]['group_id']);
                
                $data['my_groups'][$i]['admins'] = $admins;
            }
            
            $data['more_groups'] = $this->subscription_m->get_groups_notby($data['user_id']);
            
            $this->load->view('authenticated/fragments/header_v', $data);
            $this->load->view('authenticated/groups_v', $data);
            $this->load->view('administrator/fragments/footer_v', $data);
        }
        
        function search_group() {
            $data['title'] = "No Group Found";
            if($_POST['txt_goToGroup'] == null || $_POST['txt_goToGroup'] == "") {
                redirect('authenticated/groups');
            }
            else {
                $search_string = $_POST['txt_goToGroup'];
                $group_id = $this->groups_m->get_group_id_result($search_string);
                
                if($group_id != null) {
                    $group_id = $group_id[0]['group_id'];
                    $this->one_group($group_id);
                }
                else {
                    $this->load->view('authenticated/fragments/header_v', $data);
                    
                    $data['user_id'] = $this->session->userdata('user_id');
                    $data['role_id'] = $this->session->userdata('role_id');
                    $data['rolename'] = $this->session->userdata('rolename');
                    //$dept_id = $this->session->userdata('dept_id');

                    $data['my_groups'] = $this->subscription_m->get_groups_subscribed_by_order_name($data['user_id']);

                    for($i = 0; $i < count($data['my_groups']); $i++) {
                        $admins = $this->groups_m->getGroupAdmins($data['my_groups'][$i]['group_id']);

                        $data['my_groups'][$i]['admins'] = $admins;
                    }

                    $data['more_groups'] = $this->subscription_m->get_groups_notby($data['user_id']);

                    $this->load->view('authenticated/no_group_v', $data);
                    $this->load->view('authenticated/groups_v', $data);
                    $this->load->view('administrator/fragments/footer_v', $data);
                }
            }
        }
        
        //DON'T DELETE THIS YET! :)
//        function find_group() {
//            $data['title'] = 'Welcome to the SCIS Bulletin Board';
//            $data['user_id'] = $this->session->userdata('user_id');
//            $data['role_id'] = $this->session->userdata('role_id');
//            $data['rolename'] = $this->session->userdata('rolename');
//            
//            if(empty($_POST['txtSearchJoinedGroup'])) {
//                $data['search_string'] = $_POST['txtSearchJoinedGroup'];
//                $data['my_groups'] = $this->subscription_m->get_searched_groups($data['user_id'], $data['search_string']);
//
//                for($i = 0; $i < count($data['my_groups']); $i++) {
//                    $admins = $this->groups_m->getGroupAdmins($data['my_groups'][$i]['group_id']);
//                    $data['my_groups'][$i]['admins'] = $admins;
//                }
//
//                $data['more_groups'] = $this->subscription_m->get_groups_notby($data['user_id']);
//
//                $this->load->view('authenticated/fragments/header_v', $data);
//                $this->load->view('authenticated/groups_v', $data);
//                $this->load->view('administrator/fragments/footer_v', $data);
//            }
//        }
        
        function subscribe_to($group_id) {
            $selected_subs = array( '[0]' => $this->session->userdata('user_id'));
            $is_forced = 0;
            $this->subscription_m->insert_subscriber($group_id, $selected_subs, $is_forced);
            
            redirect('authenticated/groups');
        }
        
        function confirm_unsubscribe($group_id) {
            $data['title'] = 'Confirm Unsubscribe';
            $data['group_to_unsubscribe'] = $this->groups_m->get_group($group_id);
            $this->load->view('authenticated/fragments/header_v', $data);
            $this->load->view('administrator/fragments/footer_v', $data);
            
            if(!isset($_POST['btn_confirm']) && !isset($_POST['btn_cancel_unsubscribe'])) {
                $data['error_message'] = "";
                $this->load->view('authenticated/confirm_unsubscribe', $data);
            }
        }
        
        function unsubscribe_to($group_id) {
            $my_password = $this->session->userdata('password');
            
            $data['title'] = 'Confirm Unsubscribe';
            $data['group_to_unsubscribe'] = $this->groups_m->get_group($group_id);
            $this->load->view('authenticated/fragments/header_v', $data);
            $this->load->view('administrator/fragments/footer_v', $data);
            
            if(isset($_POST['btn_confirm'])) {
                if(sha1($_POST['txtPassword']) != $my_password) {
                    $data['error_message'] = "Password incorrect!";
                    $this->load->view('authenticated/confirm_unsubscribe', $data);
                }
                else if(sha1($_POST['txtPassword']) == $my_password) {
                    $selected_unsubs = array( '[0]' => $this->session->userdata('user_id'));
                    $is_forced = 0;
                    $this->subscription_m->delete_subsciber($group_id, $selected_unsubs);

                    redirect('authenticated/groups');
                }
            }
            else if(isset($_POST['btn_cancel_unsubscribe'])) {
                redirect('authenticated/groups');
            }
        }
        
        
        function one_group($group_id) {
            $data['group_id'] = $group_id;
            $data['title'] = "My Groups";
            $data['role_id'] = $this->session->userdata('role_id');
            $data['rolename'] = $this->session->userdata('rolename');
            $data['group_info'] = $this->groups_m->get_group($group_id);
            $data['segment'] = $this->uri->segment(2);

            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            
            $config = array();
            $config["base_url"] = site_url('authenticated/groups/'.$this->uri->segment(3));
            $config["total_rows"] = sizeof($this->groups_m->get_group_posts($group_id));
            $config["per_page"] = 4;
            $config["uri_segment"] = 4;
            $config['full_tag_open'] = '<span id=page_link>';
            $config['full_tag_close'] = '</span>';
            $config['first_link'] = 'First';
            $config['first_tag_open'] = '<span id=first_link>';
            $config['first_tag_close'] = '</span>';
            $config['last_link'] = 'Last';
            $config['last_tag_open'] = '<span id=last_link>';
            $config['last_tag_close'] = '</span>';
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span id=prev_link>';
            $config['prev_tag_close'] = '</span>';
            $config['next_link'] = 'Next';
            $config['nex_tag_open'] = '<span id=next_link>';
            $config['next_tag_close'] = '</span>';

            $this->pagination->initialize($config);

            $page = $this->uri->segment(3) ? $this->uri->segment(4) : 0;
            $data["posts"] = $this->groups_m->get_group_posts_limit($config["per_page"], $page, $group_id);
            $data["links"] = $this->pagination->create_links();
            
            $this->load->view('authenticated/one_group', $data);
            $this->load->view('footer_v', $data);
        }
        
        
        function profile($idno) {
            $data['title'] = "My Profile";
            $user = $this->user_m->get_user($idno);
            $data['error'] = $this->session->flashdata('error');
            $data['success'] = $this->session->flashdata('success');
            
            $this->form_validation->set_rules('old_pass', 'Old Passowrd', 'required|xss_clean');
            $this->form_validation->set_rules('new_pass', 'New Passowrd', 'required|xss_clean');
            $this->form_validation->set_rules('conf_pass', 'Confirm Passowrd', 'required|xss_clean');
            
            if($this->form_validation->run() === TRUE){
                if(isset($_POST) && !empty($_POST)){
                    $old_pass = $this->input->post('old_pass');
                    $conf_pass = $this->input->post('conf_pass');
                    $pass = $this->user_m->get_old_pass($idno);
                    if($pass['password'] === sha1($old_pass)) {
                        $this->user_m->change_password($idno, $conf_pass);
                        $this->session->set_flashdata('success', 'Password successfully changed.');
                        redirect('authenticated/profile/'.$idno);
                    }else{
                        $this->session->set_flashdata('error', 'Old password is incorrect.');
                        redirect('authenticated/profile/'.$idno);
                    }
                }
            } else {
                $data['idno'] = array(
                  'name' => 'idno',
                  'id' => 'idno',
                  'type' => 'text',
                  'value' => $user['idno'],
                  'readonly' => 'readonly'
                );

                $data['fname'] = array(
                    'name' => 'fname',
                    'id' => 'fname',
                    'type' => 'text',
                    'value' => $user['fname'],
                    'readonly' => 'readonly'
                );

                $data['mname'] = array(
                    'name' => 'mname',
                    'id' => 'mname',
                    'type' => 'text',
                    'value' => $user['mname'],
                    'readonly' => 'readonly'
                );

                $data['lname'] = array(
                    'name' => 'lname',
                    'id' => 'lname',
                    'type' => 'text',
                    'value' => $user['lname'],
                    'readonly' => 'readonly'
                );

                $data['old_pass'] = array(
                    'name' => 'old_pass',
                    'id' => 'old_pass',
                    'type' => 'text',
                );

                $data['new_pass'] = array(
                    'name' => 'new_pass',
                    'id' => 'new_pass',
                    'type' => 'text',
                );

                $data['conf_pass'] = array(
                    'name' => 'conf_pass',
                    'id' => 'conf_pass',
                    'type' => 'text',
                    'onkeyup' => 'validate_new_pass()'
                );

                $data['save'] = array(
                    'name' => 'save',
                    'id' => 'btn_save',
                    'type' => 'submit',
                    'value' => 'Save'
                ); 
            
                if($this->session->userdata('logged_in')) {
                  $this->load->view('authenticated/fragments/header_v', $data);
                } else {
                  $this->load->view('header_v', $data);
                }
                $this->load->view('authenticated/edit_user_v', $data);
                $this->load->view('footer_v', $data);
            }
        }
        
        function read_full_story($post_id) {
            $data['title'] = 'Welcome to the SCIS Group Post';
            $data['years'] = $this->post_m->get_year();
            $data['group_info'] = $this->groups_m->get_all_subscribed_groups($this->session->userdata('user_id'));
            $data['segment'] = $this->uri->segment(2);
            $data['full_story'] = $this->post_m->get_bulletin_full_text_post($post_id);
            $data['day'] = array(
                'name' => 'day',
                'id' => 'day_filter',
                'type' => 'text'
            );
            $data['submit_day'] = array(
                'name' => 'submit_day',
                'id' => 'submit_day_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['year'] = array(
                'name' => 'year',
                'id' => 'year_filter',
                'type' => 'text'
            );
            $data['submit_year'] = array(
                'name' => 'submit_year',
                'id' => 'submit_year_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['img'] = array(
                'src' => 'resources/images/backButton.png',
                'alt' => ':)',
                'id' => 'back_image'
            );
            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            $this->load->view('authenticated/full_story', $data);
            $this->load->view('footer_v', $data);
        }
        
        function all_group_post_by_year($year) {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
//            $data['bulletin'] = $this->post_m->get_all_bulletin_post();
            $data['years'] = $this->post_m->get_year();
            $data['group_info'] = $this->groups_m->get_all_subscribed_groups($this->session->userdata('user_id'));
            $data['segment'] = $this->uri->segment(2);
            $data['day'] = array(
                'name' => 'day',
                'id' => 'day_filter',
                'type' => 'text'
            );
            $data['submit_day'] = array(
                'name' => 'submit_day',
                'id' => 'submit_day_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['year'] = array(
                'name' => 'year',
                'id' => 'year_filter',
                'type' => 'text'
            );
            $data['submit_year'] = array(
                'name' => 'submit_year',
                'id' => 'submit_year_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            
            $config = array();
            $config["base_url"] = site_url('/authenticated_page_c/index');
            $config["total_rows"] = sizeof($this->post_m->all_group_post($this->session->userdata('user_id')));
            $config["per_page"] = 5;
            $config["uri_segment"] = 3;
            $config['num_links'] = 10;
            $config['full_tag_open'] = '<span id=page_link>';
            $config['full_tag_close'] = '</span>';
            $config['first_link'] = 'First';
            $config['first_tag_open'] = '<span id=first_link>';
            $config['first_tag_close'] = '<span>';
            $config['last_link'] = 'Last';
            $config['last_tag_open'] = '<span id=last_link>';
            $config['last_tag_close'] = '<span>';
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span id=prev_link>';
            $config['prev_tag_close'] = '<span>';
            $config['next_link'] = 'Next';
            $config['nex_tag_open'] = '<span id=next_link>';
            $config['next_tag_close'] = '<span>';

            $this->pagination->initialize($config);

            $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            /*$data["bulletin"] = $this->post_m->fetch_all_bulletin_post($config["per_page"], $page, $this->session->userdata('user_id'));*/
            $data["links"] = $this->pagination->create_links();
            $data["bulletin"] = $this->post_m->get_group_posts_by_year($year, $this->session->userdata('user_id'),$config["per_page"], $page);
            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            $this->load->view('authenticated/bulletin_v', $data);
            $this->load->view('footer_v', $data);
        }
        
        function all_group_post() {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
            $data['location'] = 'SCIS Bulletin Board Post';
            $result = $this->post_m->count_group_post($this->session->userdata('user_id'));
            $data['years'] = $this->post_m->get_year();
            $data['group_info'] = $this->groups_m->get_all_subscribed_groups($this->session->userdata('user_id'));
            $data['segment'] = $this->uri->segment(2);
            $data['header_title'] = "Group Posts";
            $data['day'] = array(
                'name' => 'day',
                'id' => 'day_filter',
                'type' => 'text'
            );
            $data['submit_day'] = array(
                'name' => 'submit_day',
                'id' => 'submit_day_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['year'] = array(
                'name' => 'year',
                'id' => 'year_filter',
                'type' => 'text'
            );
            $data['submit_year'] = array(
                'name' => 'submit_year',
                'id' => 'submit_year_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['img'] = array(
                'src' => 'resources/images/sad_face.jpg',
                'alt' => ':)',
                'class' => 'post_images',
                'width' => '40%',
                'height' => '300',
            );
            
            $config = array();
            $config["base_url"] = site_url('/authenticated_page_c/all_group_post');
            $config["total_rows"] = sizeof($this->post_m->all_group_post($this->session->userdata('user_id')));
            $config["per_page"] = 5;
            $config["uri_segment"] = 3;
            $config['num_links'] = 10;
            $config['full_tag_open'] = '<span id=page_link>';
            $config['full_tag_close'] = '</span>';
            $config['first_link'] = 'First';
            $config['first_tag_open'] = '<span id=first_link>';
            $config['first_tag_close'] = '<span>';
            $config['last_link'] = 'Last';
            $config['last_tag_open'] = '<span id=last_link>';
            $config['last_tag_close'] = '<span>';
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span id=prev_link>';
            $config['prev_tag_close'] = '<span>';
            $config['next_link'] = 'Next';
            $config['nex_tag_open'] = '<span id=next_link>';
            $config['next_tag_close'] = '<span>';

            $this->pagination->initialize($config);


            $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $data["bulletin"] = $this->post_m->fetch_group_posts($config["per_page"], $page, $this->session->userdata('user_id'));
            $data["links"] = $this->pagination->create_links();
            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            if($result !== 0) {
                $this->load->view('authenticated/bulletin_v', $data);
            } else {
                $this->load->view('authenticated/result_empty', $data);
            }
            $this->load->view('footer_v', $data);
        }
        
        function all_bulletin_post() {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
            $result = $this->post_m->count_bulletin_post();
            $data['years'] = $this->post_m->get_year();
            $data['group_info'] = $this->groups_m->get_all_subscribed_groups($this->session->userdata('user_id'));
            $data['segment'] = $this->uri->segment(2);
            $data['header_title'] = "Bulletin Posts";
            $data['day'] = array(
                'name' => 'day',
                'id' => 'day_filter',
                'type' => 'text'
            );
            $data['submit_day'] = array(
                'name' => 'submit_day',
                'id' => 'submit_day_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['year'] = array(
                'name' => 'year',
                'id' => 'year_filter',
                'type' => 'text'
            );
            $data['submit_year'] = array(
                'name' => 'submit_year',
                'id' => 'submit_year_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['img'] = array(
                'src' => 'resources/images/sad_face.jpg',
                'alt' => ':)',
                'class' => 'post_images',
                'width' => '40%',
                'height' => '300',
            );
            
            $config = array();
            $config["base_url"] = site_url('/authenticated_page_c/all_bulletin_post');
            $config["total_rows"] = sizeof($this->post_m->get_all_bulletin_post());
            $config["per_page"] = 5;
            $config["uri_segment"] = 3;
            $config['num_links'] = 10;
            $config['full_tag_open'] = '<span id=page_link>';
            $config['full_tag_close'] = '</span>';
            $config['first_link'] = 'First';
            $config['first_tag_open'] = '<span id=first_link>';
            $config['first_tag_close'] = '<span>';
            $config['last_link'] = 'Last';
            $config['last_tag_open'] = '<span id=last_link>';
            $config['last_tag_close'] = '<span>';
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span id=prev_link>';
            $config['prev_tag_close'] = '<span>';
            $config['next_link'] = 'Next';
            $config['nex_tag_open'] = '<span id=next_link>';
            $config['next_tag_close'] = '<span>';

            $this->pagination->initialize($config);

            $page = ($this->uri->segment(3)) != "posts" && ($this->uri->segment(3) != null) ? $this->uri->segment(3) : 0;
            $data["bulletin"] = $this->post_m->fetch_all_bulletin_post($config["per_page"], $page);
            $data["links"] = $this->pagination->create_links();
            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            if($result !== 0) {
                $this->load->view('authenticated/bulletin_v', $data);
            } else {
                $this->load->view('authenticated/result_empty', $data);
            }
            $this->load->view('footer_v', $data);
        }
        
        function filter_bulletin_post_by_year($year, $category) {
            $data['title'] = 'Welcome to the SCIS Bulletin Board';
            $data['years'] = $this->post_m->get_year();
            $result = $this->post_m->count_posts_by_year($year);
            $data['group_info'] = $this->groups_m->get_all_subscribed_groups($this->session->userdata('user_id'));
            $data['segment'] = $this->uri->segment(2);
            $data['header_title'] = "Results";
            $data['day'] = array(
                'name' => 'day',
                'id' => 'day_filter',
                'type' => 'text'
            );
            $data['submit_day'] = array(
                'name' => 'submit_day',
                'id' => 'submit_day_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['year'] = array(
                'name' => 'year',
                'id' => 'year_filter',
                'type' => 'text'
            );
            $data['submit_year'] = array(
                'name' => 'submit_year',
                'id' => 'submit_year_filter',
                'type' => 'submit',
                'value' => 'FIND'
            );
            $data['img'] = array(
                'src' => 'resources/images/sad_face.jpg',
                'alt' => ':)',
                'class' => 'post_images',
                'width' => '40%',
                'height' => '300',
            );
            
            $config = array();
            $config["base_url"] = site_url('authenticated_page_c/filter_bulletin_post_by_year/'.$year."/".$category);
            $config["total_rows"] = sizeof($this->post_m->get_bulletin_posts_by_year($year));
            $config['uri_segment'] = 5;
            $config["per_page"] = 5;
            $config['full_tag_open'] = '<span id=page_link>';
            $config['full_tag_close'] = '</span>';
            $config['first_link'] = 'First';
            $config['first_tag_open'] = '<span id=first_link>';
            $config['first_tag_close'] = '<span>';
            $config['last_link'] = 'Last';
            $config['last_tag_open'] = '<span id=last_link>';
            $config['last_tag_close'] = '<span>';
            $config['prev_link'] = 'Previous';
            $config['prev_tag_open'] = '<span id=prev_link>';
            $config['prev_tag_close'] = '<span>';
            $config['next_link'] = 'Next';
            $config['nex_tag_open'] = '<span id=next_link>';
            $config['next_tag_close'] = '<span>';
            $this->pagination->initialize($config);
            $page = ($this->uri->segment(5) != "") ? $this->uri->segment(5) : 0;
            if($this->uri->segment(4) == "index"){
                $data["bulletin"] = $this->post_m->fetch_bulletin_posts_by_year($config["per_page"], $page, $year,$category, $this->session->userdata('user_id'));
            }else if($this->uri->segment(4) == "authen"){
                $data["bulletin"] = $this->post_m->fetch_bulletin_posts_by_year($config["per_page"], $page, $year,$category, $this->session->userdata('user_id'));
            }else if($this->uri->segment(4) == "bulletin"){
                $data["bulletin"] = $this->post_m->fetch_bulletin_posts_by_year($config["per_page"], $page, $year,$category, $this->session->userdata('user_id'));
            }else{
                $data["bulletin"] = $this->post_m->fetch_bulletin_posts_by_year($config["per_page"], $page, $year,$category, $this->session->userdata('user_id'));
            }    
            $data["links"] = $this->pagination->create_links();
            if($this->session->userdata('logged_in')) {
              $this->load->view('authenticated/fragments/header_v', $data);
            } else {
              $this->load->view('header_v', $data);
            }
            if($result !== 0) {
                $this->load->view('authenticated/bulletin_v', $data);
            } else {
                $this->load->view('authenticated/result_empty', $data);
            }
            $this->load->view('footer_v', $data);
        }
    }
 ?>
